package com.yztc.yidoutang.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.yidoutang.R;
import com.yztc.yidoutang.bean.GoodsBean;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 普通的展示商品的RecyclerView的适配器
 */
public class NormalRecycleAdapter extends RecyclerView.Adapter<NormalRecycleAdapter.ViewHolder> {
    private Context context;
    private List<GoodsBean> list;

    public NormalRecycleAdapter(Context context, List<GoodsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recycleitem_normal, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        GoodsBean goods = list.get(position);
        Glide.with(context).load(goods.getSmallImage()).into(holder.image);
        Glide.with(context).load(goods.getUserPic()).into(holder.header);
        holder.title.setText(goods.getCaseTitle());
        holder.name.setText(goods.getUserName());
        holder.num.setText(goods.getFavtimes());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView image;
        TextView title;
        CircleImageView header;
        TextView name;
        CheckBox collect;
        TextView num;

        public ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.find_recycleitem_iv_image);
            title = (TextView) itemView.findViewById(R.id.find_recycleitem_tv_title);
            header = (CircleImageView) itemView.findViewById(R.id.find_recycleitem_iv_header);
            name = (TextView) itemView.findViewById(R.id.find_recycleitem_tv_name);
            collect = (CheckBox) itemView.findViewById(R.id.find_recycleitem_cb_collect);
            num = (TextView) itemView.findViewById(R.id.find_recycleitem_tv_num);
        }
    }
}